package com.ruoyi.project.distribute.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.project.distribute.domain.HosDocumentmsg;
import com.ruoyi.project.distribute.mapper.HosDocumentmsgMapper;
import com.ruoyi.project.distribute.service.IHosDocumentmsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author anran
 */
@Service
public class HosDocumentmsgServiceImpl implements IHosDocumentmsgService
{
    @Autowired
    private HosDocumentmsgMapper hosDocumentmsgMapper;

    /**
     * 查询单据详细信息
     *
     * @return
     */
    @Override
    public List<HosDocumentmsg> selectHosDocumentmsgList(String documentlogId)
    {
        return hosDocumentmsgMapper.selectHosDocumentmsgList(documentlogId);
    }

    /**
     * 单据信息表添加药品信息
     *
     * @param documentlogId
     * @param drugId
     * @return
     */
    @Override
    public int insertDocumentMsgByDocumentMsgIdAndDrugId(String documentlogId, Long drugId)
    {
        HosDocumentmsg hosDocumentMsgResult= hosDocumentmsgMapper.selectDocumentMsgByDocumentMsgIdAndDrugIdList(documentlogId, drugId);
        Integer i = 3;
        if(hosDocumentMsgResult != null){
            return i;
        }
        else
        {
            HosDocumentmsg hosDocumentmsg = new HosDocumentmsg();
            hosDocumentmsg.setDocumentlogId(documentlogId);
            hosDocumentmsg.setDrugId(drugId);
            hosDocumentmsg.setCreateBy(SecurityUtils.getUsername());
            hosDocumentmsg.setCreateTime(DateUtils.getNowDate());
            hosDocumentmsg.setDocumentmsgNum(0);
            hosDocumentmsg.setDocumentmsgTotal(0);
            return hosDocumentmsgMapper.insertDocumentMsgByDocumentMsgIdAndDrugId(hosDocumentmsg);
        }
    }

    /**
     * 删除单据 ID 信息表中 药品信息
     *
     * @param documentlogId
     * @param drugId
     * @return
     */
    @Override
    public int deleteHosDocumentMsgByDocumentMsgIdAndDrugId(String documentlogId, Long drugId)
    {
        return hosDocumentmsgMapper.deleteHosDocumentMsgByDocumentMsgIdAndDrugId(documentlogId, drugId);
    }

}
